package com.xebest.web.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.xebest.web.mapper.read.XeUserTypeReadMapper;
import com.xebest.web.mapper.write.XeUserTypeWriteMapper;
import com.xebest.web.model.XeUserTypeEntity;
import com.xebest.web.service.XeUserTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class XeUserTypeServiceImpl implements XeUserTypeService {
	
	@Autowired
	private XeUserTypeWriteMapper xeUserTypeWriteMapper;
    @Autowired
    XeUserTypeReadMapper xeUserTypeReadMapper;

	@Override
	public int insertUserType(XeUserTypeEntity entity) throws Exception{
		int count = xeUserTypeWriteMapper.insertUserType(entity);  
		return count;
	}

	@Override
	public int updateByTypeId(XeUserTypeEntity entity) throws Exception{
		int count = xeUserTypeWriteMapper.updateByTypeId(entity);  
		return count;
	}

	@Override
	public List<XeUserTypeEntity> deleteByTypeIds(List<Integer>  list, String modifyUser) throws Exception {
		// 如果用户类型已经被使用，则不能删除
		 List<XeUserTypeEntity> typeList = xeUserTypeReadMapper.getInUseByTypeIds(list);
		if(typeList != null && typeList.size() > 0){
			return typeList;
		} else {
			xeUserTypeWriteMapper.deleteByTypeIds(list, modifyUser); 
			return null;
		}
	}

}
